<?php 
include('conexion.php');

$fechade = $_POST['fechade'];
$tiempo = explode ("/", $fechade);
$desde = $tiempo[2] . "-" . $tiempo[1] . "-" . $tiempo[0];

$fechaa = $_POST['fechaa'];
$tiempo2 = explode ("/", $fechaa);
$hasta = $tiempo2[2] . "-" . $tiempo2[1] . "-" . $tiempo2[0];

/*
<td width="70" height="19" bgcolor="#CCCCCC"><span class="Estilo14">Numero</span></td>
<td width="86" bgcolor="#CCCCCC"><span class="Estilo14">Fec. Ingr.        </span></td>
<td width="86" bgcolor="#CCCCCC"><span class="Estilo14">Fec. Dilig.       </span></td>
<td width="93" bgcolor="#CCCCCC"><span class="Estilo14">Zona              </span></td>
<td width="171" bgcolor="#CCCCCC"><span class="Estilo14">Remitente        </span></td>
<td width="275" bgcolor="#CCCCCC"><span class="Estilo14">Destinatario     </span></td>
*/

$consulta = mysql_query("SELECT num_carta, DATE_FORMAT(STR_TO_DATE(fec_ingreso,'%d/%m/%Y'),'%d/%m/%Y'), fec_entrega, nom_remitente, nom_destinatario,zona_destinatario FROM ingreso_cartas WHERE STR_TO_DATE(fec_ingreso,'%d/%m/%Y') BETWEEN STR_TO_DATE('$fechade','%d/%m/%Y') AND STR_TO_DATE('$fechaa','%d/%m/%Y') ORDER BY num_carta asc", $conn) or die(mysql_error());

while($row = mysql_fetch_array($consulta)){

$numcarta = $row[0];
$numcarta2 = substr($numcarta,5,6).'-'.substr($numcarta,0,4);

echo"<table width='834' border='1' cellpadding='0' cellspacing='0' bordercolor='#E5E5E5'>
  <tr>
    <td width='70'  height='19' valign='top'><span class='Estilo12'>".$numcarta2."</span></td>
    <td width='86'  valign='top'><span class='Estilo12'>".$row[1]."</span></td>
    <td width='86'  valign='top'><span class='Estilo12'>".$row[2]."</span></td>
    <td width='93'  valign='top'><span class='Estilo12'>";
	
	$consulta2 = mysql_query("SELECT ubigeo.nomdis FROM ubigeo WHERE ubigeo.coddis='".$row[5]."' ", $conn) or die(mysql_error());
	while($row2 = mysql_fetch_array($consulta2)){
		echo $row2[0];
	}
	 echo"</span></td>
    <td width='171' valign='top'><span class='Estilo12'>".$row[3]."</span></td>
    <td width='275' valign='top'><span class='Estilo12'>".$row[4]."</span></td>
  </tr>
</table>";
}

?>